import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yqys_target/gen/assets.gen.dart';
import 'package:yqys_target/pages/organization/controllers/organization_auth_controller.dart';
import 'package:yqys_target/utils/yq_colors.dart';
import 'package:yqys_target/widgets/xh_auto_height_text_field.dart';
import '../../../../widgets/form_list_item.dart';
import '../../../../widgets/yq_upload_images.dart';

class BasicInfoPage extends StatelessWidget {
  const BasicInfoPage({super.key});

  @override
  Widget build(BuildContext context) {
    final controller = Get.find<OrganizationAuthController>();

    return SingleChildScrollView(
      padding: const EdgeInsets.all(16),
      child: DefaultTextStyle(
        style: TextStyle(fontSize: 15, color: YQColors.primary),
        child: Column(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                color: Colors.white,
                child: Column(
                  children: [
                    FormListItem(
                      title: "机构标识",
                      trailing: const Icon(Icons.circle_notifications),
                    ),
                    FormListItem(
                      title: "机构名称",
                      trailing: XHAutoHeightTextField(
                        maxLength: 30,
                        width: 200,
                        placeholder: "请输入机构名称",
                      ),
                    ),
                    FormListItem(
                      title: "法人姓名",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入法人姓名",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "法人身份证号",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入法人身份证号",
                        ),
                      ),
                    ),
                    FormListItem(
                      title: "联系电话",
                      trailing: SizedBox(
                        width: 200,
                        child: XHAutoHeightTextField(
                          maxLength: 30,
                          width: 200,
                          placeholder: "请输入联系电话",
                        ),
                      ),
                    ),
                    const SizedBox(height: 20),
                    _IDCardUploadWidget(),
                  ],
                ),
              ),
            ),
            const SizedBox(height: 20),
            Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(10),
              ),
              child: _UploadOrganizationPicWidget(controller: controller),
            ),
          ],
        ),
      ),
    );
  }
}

class _UploadOrganizationPicWidget extends StatelessWidget {
  const _UploadOrganizationPicWidget({
    super.key,
    required this.controller,
  });

  final OrganizationAuthController controller;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<OrganizationAuthController>(
      init: controller,
      builder: (controller) => YQUploadImages(
        images: controller.images,
        onDelete: (index) {
          controller.deleteImage(index);
        },
        onImagePicked: (source) {
          controller.handleImagePicked(source);
        },
      ),
    );
  }
}

class _IDCardUploadWidget extends StatelessWidget {
  const _IDCardUploadWidget({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 16),
        child: Column(
          children: [
            AspectRatio(
                aspectRatio: 286.0 / 166.0,
                child: Image.asset(Assets.images.idcardBg.path)),
            const SizedBox(
              height: 20,
            ),
            const Text(
              "点击上传法人身份证原件人像面",
              style: TextStyle(
                  color: Colors.green,
                  fontSize: 15,
                  fontWeight: FontWeight.bold),
            ),
            const SizedBox(
              height: 20,
            ),
            AspectRatio(
                aspectRatio: 286.0 / 166.0,
                child: Image.asset(Assets.images.idcardReverseBg.path)),
            const SizedBox(
              height: 20,
            ),
            const Text(
              "点击上传法人身份证原件国徽面",
              style: TextStyle(
                  color: Colors.green,
                  fontSize: 15,
                  fontWeight: FontWeight.bold),
            ),
          ],
        ));
  }
}
